﻿var com = {
    _cConfig: {
        _onlog: true //true:using log false:opposite
    },
    _cLog: function (_tit, _msg, _type) {
        if (!com._cConfig._onlog) {

            return;
        }
        if (Object.hasOwnProperty.call(window, "log")) {
            var _info = _tit + ":" + _msg;
            switch (_type) {
                case "info":
                    log.info(_info);
                    break;
                case "error":
                    log.error(_info);
                    break;
                case "debug":
                    log.debug(_info);
                    break;
                default:
                    log.warn(_info);
                    break;
            }
        }
    },
    _cGetXmlObj: function (_xml) {
        var xmlDoc;
        try //Internet Explorer
            {
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async = "false";
            if (_xml.charAt(0) == "<") {
                xmlDoc.loadXML(_xml);
            }
            else {
                xmlDoc.load(_xml);
            }
        }
        catch (e) {
            try //Firefox, Mozilla, Opera, etc.
               {
                parser = new DOMParser();
                xmlDoc = parser.parseFromString(_xml, "text/xml");
            }
            catch (e) {
                com._cLog("_cGetXmlObj", e.description, "error");
            }
        }
        return $(xmlDoc);
    },
    _cSetCookie: function (_n, _v) {
        try {
            var expdate = new Date();
            var argv = SetCookie.arguments;
            var argc = SetCookie.arguments.length;
            var expires = (argc > 2) ? argv[2] : null;
            var path = (argc > 3) ? argv[3] : null;
            var domain = (argc > 4) ? argv[4] : null;
            var secure = (argc > 5) ? argv[5] : false;
            expdate.setTime(expdate.getTime() + (1000 * 24 * 3600 * 1000)); //1000天后过期
            document.cookie = _n + "=" + escape(_v) + ((expires == null) ? ("; expires=" + expdate.toGMTString()) : ("; expires=" + expdate.toGMTString()))
            + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain))
            + ((secure == true) ? "; secure" : "");
        } catch (e) {
            com._cLog("_cSetCookie", e.description, "error");
        }
    },
    _cDelCookie: function (_n) {
        try {
            var exp = new Date();
            exp.setTime(exp.getTime() - 1);
            var cval = GetCookie(_n);
            document.cookie = _n + "=" + cval + "; expires=" + exp.toGMTString();
        } catch (e) {
            com._cLog("_cDelCookie", e.description, "error");
        }
    },
    _cGetCookie: function (_n) {
        try {
            var arg = _n + "=";
            var alen = arg.length;
            var clen = document.cookie.length;
            var i = 0;
            while (i < clen) {
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg)
                    return GetCookieVal(j);
                i = document.cookie.indexOf(" ", i) + 1;
                if (i == 0) break;

            }
            return null;
        } catch (e) {
            com._cLog("_cDelCookie", e.description, "error");
        }
    },
    _cGetCookieVal: function (_o) {
        try {
            var endstr = document.cookie.indexOf(";", _o);
            if (endstr == -1)
                endstr = document.cookie.length;
            return unescape(document.cookie.substring(_o, endstr));
        } catch (e) {
            com._cLog("_cDelCookie", e.description, "error");
        }
    },
    _cCreateFrame: function (_u) {
        var s = '<iframe scrolling="auto" frameborder="0"  src="' + _u + '" style="width:100%;height:100%;"></iframe>';
        return s;
    },
    _cInitFrame: function () {
        $('body').height($('html').height() * 0.99);
    },
    _cRndNum: function (_n) {
        var rnd = "";
        for (var i = 0; i < _n; i++)
            rnd += Math.floor(Math.random() * 10);
        return rnd;
    },
    _cFormatPages: function (_p, _t) {
        return soul.base + "Pages/" + (com._cTrim(_p) == "" ? "400.html" : com._cTrim(_p) + "?r=" + com._cRandom() + "&g=" + _t + "");
    },
    _cTrim: function (_s) {
        return _s.replace(/(^\s*)|(\s*$)/g, "");
    },
    _cLTrim: function (_s) {
        return _s.replace(/(^\s*)/g, "");
    },
    _cRTrim: function (_s) {
        return _s.replace(/(\s*$)/g, "");
    },
    _cResizeWindow: function () {
        window.moveTo(5, 0);
        window.resizeTo(screen.availWidth / 2, screen.availHeight / 2);
    },
    _cFullScreen: function () {
        try {
            if (window.screenLeft == 0 && window.document.body.clientWidth == window.screen.width) {
            }
            else {
                var WshShell = new ActiveXObject('WScript.Shell');
                WshShell.SendKeys('{F11}');
            }
        } catch (e) {
            com._cLog("_cFullScreen", e.description, "error");
        }
    },
    _cResizeObj: function (_o, _p) {
        if (_o == undefined) {
            _o = "body";
        }
        var _obj = $(_o);
        _obj.width(_obj.parent().width() - (_p ? _p : 0)).height(_obj.parent().height() - (_p ? _p : 0));
    },
    _cFormatDateTime: function () {
        var _date = {};
        var _newdate = new Date();
        _date.year = _newdate.getFullYear();
        _date.month = _newdate.getMonth() + 1;
        _date.date = _newdate.getDate();
        _date.hour = _newdate.getHours();
        _date.minutes = _newdate.getMinutes();
        _date.seconds = _newdate.getSeconds();
        _date.day = (_newdate.getDay() == 0 ? "星期天" : (_newdate.getDay() == 1 ? "星期一" : (_newdate.getDay() == 2 ? "星期二" : (_newdate.getDay() == 3 ? "星期三" : (_newdate.getDay() == 4 ? "星期四" : (_newdate.getDay() == 5 ? "星期5" : (_newdate.getDay() == 6 ? "星期六" : null)))))))
        return _date;
    },
    _cRandom: function () {
        var sRand = "";
        for (var i = 0; i < 10; i++) {
            sRand = sRand + (parseInt(Math.random() * 9)).toString();
        }
        return sRand;
    },
    _cInitPage: function () {
        $('body').bind("contextmenu", function () {
            return false;
        });
    },
    _cGetUrlParam: function (_k) {
        var reg = new RegExp("(^|&)" + _k + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }
};